--星火
local xinghuo = fk.CreateSkill {
    name = "mcdh_xinghuo",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xinghuo:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target.phase == Player.Start and player:getMark("mcdh_charge") >= 3
    end,
    on_cost =  function(self, event, target, player, data)
        local room = player.room
        local choices = {"mcdh_xinghuo-choose1","mcdh_xinghuo-choose2","mcdh_xinghuo-choose3", "Cancel"}
        if not target:isWounded() then
            table.removeOne(choices,"mcdh_xinghuo-choose2")
        end
        if target:getMark("mcdh_charge_max") - target:getMark("mcdh_charge") <= 0 then
            table.removeOne(choices,"mcdh_xinghuo-choose3")
        end
        local choice = room:askForChoice(player, choices, self.name, "#mcdh_xinghuo-choose:"..target.id,nil,{"mcdh_xinghuo-choose1","mcdh_xinghuo-choose2","mcdh_xinghuo-choose3", "Cancel"})
        if choice ~= "Cancel" then
            self.cost_data = choice
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        lib.LoseCharge(player,player,3,self.name)
        local room = player.room
        local choice = self.cost_data
        if choice == "mcdh_xinghuo-choose1" then
            local check = U.askForUseVirtualCard(room, target, "fire_attack", nil, self.name, "#mcdh_xinghuo-use")
            if not check then
                target:drawCards(1,self.name)
            end
        elseif choice == "mcdh_xinghuo-choose2" then
            room:recover({
                who = target,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        else
            lib.RecoverCharge(player,target,2,self.name)
        end
    end
})


Fk:loadTranslationTable {
    ["mcdh_xinghuo"] = "星火",
    [":mcdh_xinghuo"] = "蓄力技(3),每名角色的准备阶段,你可以令其执行一项:1.摸一张牌或视为使用一张【火攻】;2.回复1点体力;3.回复2点技力。",
    ["#mcdh_xinghuo-choose"] = "星火:令 %src 执行一项",
    ["mcdh_xinghuo-choose1"] = "1.摸一张牌或视为使用一张【火攻】",
    ["mcdh_xinghuo-choose2"] = "2.回复1点体力",
    ["mcdh_xinghuo-choose3"] = "3.回复2点技力",
    ["#mcdh_xinghuo-use"] = "星火:视为使用一张【火攻】，取消则摸一张牌",
}

return xinghuo